package com.shangcheng.server.service;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.shangcheng.dubbo.api.SmsCouponHistoryApi;
import com.shangcheng.model.vo.PageResult;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

@Service
public class SmsCouponHistoryService {

    @DubboReference
    private SmsCouponHistoryApi smsCouponHistoryApi;
    /**
     * 根据优惠券id，使用状态，订单编号分页获取领取记录
     * @param couponId
     * @param orderSn
     * @param pageNum
     * @param pageSize
     * @param useStatus
     * @return
     */
    public PageResult list(Integer couponId, String orderSn, Integer pageNum, Integer pageSize, Integer useStatus) {
        //1.得到IPage
        IPage page = smsCouponHistoryApi.list(couponId,orderSn,pageNum,pageSize,useStatus);
        //2.创建PageResult
        PageResult pr = new PageResult();
        //3.封装PageResult
        pr.setList(page.getRecords());
        pr.setTotal(Convert.toInt(page.getTotal()));
        pr.setPageNum(pageNum);
        pr.setPageSize(pageSize);
        pr.setTotalPage(Convert.toInt(page.getPages()));
        return pr;
    }
}
